<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>结构编辑</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="${ctxPath}/lib/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctxPath}/css/public.css" media="all">
</head>

<body>
	<div class="layuimini-container">
		<div class="layuimini-main">

			<form class="layui-form" lay-filter="formInfo">
				<input type="hidden" name="id" id="id" class="id layui-input" />

				<div class="layui-row">
					<div class="layui-col-md12">
						<label class="layui-form-label">机构名称</label>
						<div class="layui-input-block">
							<input type="text" id="name" name="name" lay-verType="tips" required lay-verify="required"
								lay-reqtext="机构名不能够为空 !" autocomplete="off" placeholder="请输入机构名称" class="layui-input" />
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-md12">
						<label class="layui-form-label">机构编码</label>
						<div class="layui-input-block">
							<input type="text" id="code" name="code" lay-verType="tips" required lay-verify="required"
								lay-reqtext="机构编码不能够为空 !" autocomplete="off" placeholder="请输入机构编码"
								class="layui-input" />
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-md12">
						<label class="layui-form-label">上级机构</label>
						<div class="layui-input-block">
							<select name="pid" id="pid">
								<option value=""></option>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-md12">
						<label class="layui-form-label">排序</label>
						<div class="layui-input-block">
							<input type="text" id="sort" name="sort" value="100" placeholder="越大越靠前"
								class="layui-input" />
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-md12">
						<label class="layui-form-label">描述</label>
						<div class="layui-input-block">
							<textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea"></textarea>
						</div>
					</div>

				</div>
				<div class="layui-row">
					<div class="layui-col-md12">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit="" lay-filter="btn-form-submit">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</div>
			</form>

		</div>
	</div>

	<script src="${ctxPath}/lib/layui/layui.js" charset="utf-8"></script>
	<script src="${ctxPath}/js/core.util.js" charset="utf-8"></script>
	<script src="${ctxPath}/js/lay-config.js?v=2.0.0" charset="utf-8"></script>

	<script type="text/javascript">
		layui.use(['form', 'layer', 'notice'], function () {
			var $ = layui.jquery, form = layui.form, layer = layui.layer, notice = layui.notice;
		
			// 查询所有机构
			sendAjax("/sys/org/listAll", null, function (rest) {
				console.log(rest);
				$("#pid").empty().append("<option value=''>请选择上级机构</option>");
				$.each(rest.data, function (i, e) {
					$("#pid").append("<option value='" + e.id + "'>" + e.name + "</option>");
				});
				form.render('select');
			});
			
			// 获取详情信息，填充表单
			let id = request("id");
			if (id != "") {
				sendAjax("/sys/org/findById?id=" + id, null, function (result) {
					form.val('formInfo', result.data);
				}, "GET");
			}
			
			//监听提交
			form.on('submit(btn-form-submit)', function (data) {

				sendAjax("/sys/org/saveOrUpdate", JSON.stringify(data.field), function (rest) {
					notice.msg(rest.msg, {icon: 1});
				}, "POST");

				return false;
			});

		});
	</script>
</body>

</html>